package com.aco.party.web.validator.system;

import com.aco.party.enums.PostTypeEnum;
import com.aco.party.web.command.system.EditPostsCommand;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
* Created by flying on 3/10/2016 0010.
*/
public class EditPostsValidator implements Validator {
@Override
public boolean supports(Class<?> aClass) {
return EditPostsCommand.class.isAssignableFrom(aClass);
}

@Override
public void validate(Object o, Errors errors) {
    EditPostsCommand command = (EditPostsCommand)o;
    if(PostTypeEnum.普通.getValue().equals(command.getPostType())) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "postTerm", "error.postTerm.empty", "分类不能为空");
    }
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "postImg", "error.postImg.empty", "图片不能为空");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "postTitle", "error.postTitle.empty", "标题不能为空");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "postContent", "error.postContent.empty", "内容不能为空");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "postStatus", "error.postStatus.empty", "状态不能为空");
}
}
